package com.usefullc.blog.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.common.util.BeanUtils;
import com.usefullc.blog.domain.ArticleShare;
import com.usefullc.blog.mapper.ArticleShareMapper;
import com.usefullc.blog.query.ArticleShareQuery;
import com.usefullc.blog.vo.ArticleShareVo;
import com.usefullc.system.entity.Pager;
import com.usefullc.system.service.AbstractBizService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 文章分享服务类
 * @author: 星空
 * @date: 2022-07-12
 */
@Service
public class ArticleShareService extends AbstractBizService<ArticleShareMapper, ArticleShare, ArticleShareQuery> {


    @Override
    protected QueryWrapper<ArticleShare> getQueryWrapper(ArticleShareQuery query) {
        QueryWrapper<ArticleShare> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }

    public Pager<ArticleShareVo> findVoByPage(ArticleShareQuery query){
        Pager<ArticleShare> page = this.findByPage(query);
        Pager<ArticleShareVo> newPage = new Pager<>(page);
        List<ArticleShare> dataList = page.getDataList();
        List<ArticleShareVo> newDataList = new ArrayList<>();
        newPage.setDataList(newDataList);
        for (ArticleShare articleShare : dataList) {
            ArticleShareVo articleShareVo = BeanUtils.beanCopy(articleShare, ArticleShareVo.class);
            newDataList.add(articleShareVo);
        }
        return newPage;
    }


}
